/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package top.continew.admin.card.service.impl;

import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import top.continew.admin.card.mapper.CompanyIntroductionMapper;
import top.continew.admin.card.model.entity.CompanyIntroductionDO;
import top.continew.admin.card.model.query.CompanyIntroductionQuery;
import top.continew.admin.card.model.req.CompanyIntroductionReq;
import top.continew.admin.card.model.resp.CompanyIntroductionDetailResp;
import top.continew.admin.card.model.resp.CompanyIntroductionResp;
import top.continew.admin.card.service.CardIntroductionRelationService;
import top.continew.admin.card.service.CompanyIntroductionService;
import top.continew.starter.extension.crud.service.impl.BaseServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * 公司简介业务实现
 *
 * @author floyd
 * @since 2024/12/02 16:03
 */
@Service
@RequiredArgsConstructor
public class CompanyIntroductionServiceImpl extends BaseServiceImpl<CompanyIntroductionMapper, CompanyIntroductionDO, CompanyIntroductionResp, CompanyIntroductionDetailResp, CompanyIntroductionQuery, CompanyIntroductionReq> implements CompanyIntroductionService {

    @Resource
    private final CardIntroductionRelationService relationService;

    @Override
    public List<CompanyIntroductionDetailResp> getListByCardId(Long cardId) {
        List<CompanyIntroductionDetailResp> list = new ArrayList<>();

        var relationDoList = relationService.getListByCardId(cardId);
        relationDoList.forEach(item -> {
            var introductionDetailResp = super.get(item.getIntroductionId());

            list.add(introductionDetailResp);
        });

        return list;
    }
}